﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "WMS_SupplierLookUp";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div class="mvctool">
    <input id="txtSupplierCode" placeholder="代理商代码:" type="text" class="searchText" />
    <input id="txtSupplierShortName" placeholder="代理商简称:" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @Html.ToolButton("btnSave", "fa fa-plus", Resource.Select, ref perm, "Create", true)
</div>
<table>
    <tr>
        <td style="padding: 3px">
            <table id="List"></table>
        </td>
    </tr>
</table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")
<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '@(Url.Action("SupplierGetList"))',
            width: SetGridWidthSub(30),
            methord: 'post',
            height: SetGridHeightSub(47),
            nowrap: true,
            fitColumns: false,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            //pageSize: 50,
            //pageList: [50, 100],
            pageSize: 10,
            pageList: [10, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            checkOnSelect: true,
            selectOnCheck: true,
            //rownumbers: true,//行号
            onLoadSuccess: function (data) {
           @foreach(var r in perm){if(r.Category==2){@Html.Raw("$(this).datagrid('hideColumn','"+r.KeyCode+"');");}}//动态根据权限隐藏列
            },
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'Id', title: '供应商ID', width: 80, hidden: true },
                { field: 'SupplierCode', title: '供应商编码', width: 120, sortable: true },
                { field: 'SupplierShortName', title: '供应商简称', width: 150, sortable: true },
                { field: 'SupplierName', title: '供应商名称', width: 250, sortable: true },
                //{ field: 'SupplierType', title: '供应商类型', width: 80, sortable: true },
                //{ field: 'LinkMan', title: '联系人', width: 80, sortable: true },
                //{ field: 'LinkManTel', title: '联系人电话', width: 80, sortable: true },
                //{ field: 'LinkManAddress', title: '联系人地址', width: 80, sortable: true },
                //{ field: 'Status', title: '状态', width: 80, sortable: true },
                //{ field: 'Remark', title: '说明', width: 80, sortable: true },
            ]]
        });
    });

    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnQuery").click(function () {
            //var queryStr = $("#txtQuery").val();
            //if (queryStr == null) {
            //    queryStr = "%";
            //}
            //$("#List").datagrid("load", { queryStr: queryStr });
            var supplierCode = $("#txtSupplierCode").val();
            if (supplierCode == null) {
                supplierCode = "%";
            }
            var supplierShortName = $("#txtSupplierShortName").val();
            if (supplierShortName == null) {
                supplierShortName = "%";
            }
            $("#List").datagrid("load", { supplierCode: supplierCode, supplierShortName: supplierShortName});

        });
        //取得所选择的行
        $("#btnSave").click(function () {
            var rows = $('#List').datagrid('getSelections');
            if (rows.length > 0) {
                //返回到上一层处理
                window.parent.SetSelResult(rows[0].Id, rows[0].SupplierShortName);
                window.parent.frameReturnByClose();
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
    });
</script>

